package com.eagle.support.utils;

import android.content.Context;
import android.os.Handler;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import com.eagle.EApplication;


/**
 * Created by gc on 2016/12/8.
 * 软键盘操作工具
 */
public final class SoftInputKeyboardUtils {

    private SoftInputKeyboardUtils() {

    }

    /**
     * 显示软键盘
     *
     * @param view 控件
     */
    public static void showSoftInput(View view) {
        new Handler().postDelayed(() -> ((InputMethodManager) EApplication.getInstance().getApplicationContext().
                getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(view, 0), 150);
    }

    /**
     * 隐藏软键盘
     *
     * @param view 控件
     */
    public static void hideSoftInput(View view) {
        InputMethodManager inputMethodManager = (InputMethodManager) EApplication.getInstance().getApplicationContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}
